﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using SharedGenomics.Workbench.Core;
using SharedGenomics.Core;

namespace SharedGenomics.Workbench.Views.WindowsForms
{
    public class ContextMenuItemView : ToolStripMenuItem, IMenuItem
    {
        public ContextMenuItemView()
        {
            this.Click += (o, e) =>
                {
                    if (this.Command != null)
                        this.Command.Execute();
                };
        }

        #region IMenuItem Members

        public void AddSubMenu(IMenuItem menu)
        {
            ToolStripMenuItem subMenu = menu as ToolStripMenuItem;
            if (subMenu != null)
                this.DropDownItems.Add(subMenu);
            else
                throw new ArgumentException("Cannot convert menu to ToolStripMenuItem");
        }

        public ICommand Command { get; set; }

        public string DisplayText
        {
            get { return this.Text; }
            set { this.Text = value; }
        }

        public bool IsEnabled
        {
            get { return this.Enabled; }
            set { this.Enabled = value; }
        }

        public IEnumerable<IMenuItem> SubMenus
        {
            get { return this.DropDownItems.OfType<IMenuItem>(); }
        }

        #endregion
    }
}
